package com.arofoxmsn.repositories;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

public class BaseRepository<T> {
	private static SessionFactory sessionFactory;
	
	private static SessionFactory getSessionFactoryInstance(){
		if(sessionFactory == null)
			sessionFactory = new Configuration().configure().buildSessionFactory();
		return sessionFactory;
	}
	
	public static void destroySessionFactoryInstance(){
		sessionFactory =  null;
	}
	
	protected Session getSession(){
		SessionFactory factory = getSessionFactoryInstance();
		Session session = factory.openSession();
		return session;
	}
}
